package com.book.common.core.domain.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.book.common.annotation.group.InsertGroup;
import com.book.common.annotation.group.UpdateGroup;
import com.book.common.core.domain.BaseEntity;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import javax.validation.constraints.NotBlank;
import java.math.BigDecimal;
import java.util.Date;

/**
 * @ClassName AppUser * @Description TODO
 * @Author Bigboss
 * @Date 14:48 2024/10/19
 * @Version 1.0
 **/
@ApiModel(description = "用户信息表")
@TableName("app_user")
public class AppUser extends BaseEntity {

    /**
     * 主键ID
     */
    @ApiModelProperty("用户ID")
    @TableId(value = "id",type = IdType.ASSIGN_ID)
    @NotBlank(message = "请选择要修改的记录",groups = {UpdateGroup.class})
    private String id;


    /**
     * 用户头像地址
     */
    @ApiModelProperty("用户头像地址")
    private String avatar;


    /**
     * 昵称
     */
    @ApiModelProperty("用户昵称")
    private String nickName;


    /**
     * 用户姓名
     */
    @ApiModelProperty("用户姓名")
    private String name;


    /**
     * 用户联系电话（登录账号也是这个）
     */
    @ApiModelProperty("用户联系电话")
    @NotBlank(message = "请输入手机号",groups = {InsertGroup.class, UpdateGroup.class})
    private String phone;


    /**
     * 用户密码
     */
    @ApiModelProperty("用户密码")
    @JsonIgnore
    @NotBlank(message = "请输入密码",groups = {InsertGroup.class,UpdateGroup.class})
    private String password;



    /**
     * 账号注册时间
     */
    @ApiModelProperty("账号注册时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date registerTime;



    /**
     * 钱包余额
     */
    @ApiModelProperty("钱包余额")
    private BigDecimal wallet;


    /** 最后登录IP */
    @ApiModelProperty("最后登录IP")
    private String loginIp;

    /** 最后登录时间 */
    @ApiModelProperty("最后登录时间")
    private Date loginDate;


    /**
     * 最后登录的token（用于从缓存查询用户信息使用）
     */
    private String lastToken;


    /**
     * 金币数量 完成任务奖励使用
     */
    @ApiModelProperty("金币数量")
    private Integer goldCoin;

    /**
     * 删除标志（0代表存在 2代表删除）
     */
    @JsonIgnore
    @TableLogic
    private String delFlag;

    public boolean isAdmin()
    {
        return isAdmin(this.id);
    }

    public static boolean isAdmin(String userId)
    {
        return userId != null && "1".equals(userId);
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Date getRegisterTime() {
        return registerTime;
    }

    public void setRegisterTime(Date registerTime) {
        this.registerTime = registerTime;
    }

    public String getLoginIp() {
        return loginIp;
    }

    public void setLoginIp(String loginIp) {
        this.loginIp = loginIp;
    }

    public Date getLoginDate() {
        return loginDate;
    }

    public void setLoginDate(Date loginDate) {
        this.loginDate = loginDate;
    }

    public String getLastToken() {
        return lastToken;
    }

    public void setLastToken(String lastToken) {
        this.lastToken = lastToken;
    }

    public String getDelFlag() {
        return delFlag;
    }

    public void setDelFlag(String delFlag) {
        this.delFlag = delFlag;
    }

    public BigDecimal getWallet() {
        return wallet;
    }

    public void setWallet(BigDecimal wallet) {
        this.wallet = wallet;
    }

    public Integer getGoldCoin() {
        return goldCoin;
    }

    public void setGoldCoin(Integer goldCoin) {
        this.goldCoin = goldCoin;
    }

    @Override
    public String toString() {
        return "AppUser{" +
                "id='" + id + '\'' +
                ", avatar='" + avatar + '\'' +
                ", nickName='" + nickName + '\'' +
                ", name='" + name + '\'' +
                ", phone='" + phone + '\'' +
                ", password='" + password + '\'' +
                ", registerTime=" + registerTime +
                ", wallet=" + wallet +
                ", loginIp='" + loginIp + '\'' +
                ", loginDate=" + loginDate +
                ", lastToken='" + lastToken + '\'' +
                ", goldCoin=" + goldCoin +
                ", delFlag='" + delFlag + '\'' +
                '}';
    }
}
